package org.dydl.common.config;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;

public class CustomEntryPoint extends LoginUrlAuthenticationEntryPoint {
	
	public CustomEntryPoint(String loginFormUrl) {
		super(loginFormUrl);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void commence(HttpServletRequest request,
	        HttpServletResponse response, AuthenticationException authException)
	        throws IOException, ServletException {
		PrintWriter out = response.getWriter();
		out.println("<html>");    
		out.println("<script>"); 
		out.println("window.open('" + getLoginFormUrl() + "','_top');");    
		out.println("</script>");    
		out.println("</html>"); 
		response.setContentType("text/html;charset=UTF-8");
		response.getWriter().flush();
	}

}
